package parser;

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.Part;

/**
 * Cette classe extrait les mots d'une partie de message en texte brut
 *
 */
public class TextWordExtractor implements WordsExtractor
{
	private Part part;
	
	
	public TextWordExtractor(Part part)
	{
		this.part = part;
	}
	
	@Override
	public void extractWords(WordsHandler wordsHander)
	{
		String text;
		try
		{
			text = (String) part.getContent();
			Iterable<String> words = WordsSpliter.getInstance().split(text.toString());
			for (String word : words)
			{
				wordsHander.handle(new FormatedWord(word));
			}
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (MessagingException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
